package com.apts.servise;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.apts.util.MD5Util;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

/**
 * 全局备用业务操作
 * 
 * @author nice
 */
public class Servise_PlanB_ {
	public static Logger log4j = Logger.getLogger(Servise_PlanB_.class);
	
	public static final Servise_PlanB_ servise = new Servise_PlanB_();

	// ===================== 登录业务 ===========================

	public Map<String, Object> findAccount(String account, String password) {
		Map<String, Object> map = new HashMap<String, Object>(0);
		List<Record> adminSet = Db.find(" select * from tb_admin where account = ? ", account);
		// 如果存在用户
		if (adminSet.size() > 0) {
			Record admin = adminSet.get(0);
			// 获取盐值，用户密码加盐后校验
			String pwdsalt = admin.getStr("pwdsalt");
			String pwd = MD5Util.md5Encode(password + pwdsalt);
			// 密码校验正确
			if (admin.getStr("password").equals(pwd)) {
				map.put("userName", admin.getStr("userName"));
				map.put("account", admin.getStr("account"));
				map.put("email", admin.getStr("email"));
				map.put("telephone", admin.getStr("telephone"));
				map.put("headimg", admin.getStr("headimg"));
				log4j.info("执行到这里: (DB密码)" + admin.getStr("password")+"  (Input密码)"+pwd);
				return map;
			}
		}
		return null;
	}

	// ==========================================================
	
	// ========================= 用户登录保存token ===============
	
	// ==========================================================

}
